package Mycode.TireTree;

import java.util.*;

public class Leetcode421 {

    class Solution {
    public int findMaximumXOR(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        int Maxn = Integer.MIN_VALUE;
        for (int num : nums) { 
            Maxn = Math.max(num, Maxn);
        }
        int ans = 0;
        for (int i = 31 - Integer.numberOfLeadingZeros(Maxn); i >= 0; i--) { 
            int better = ans | (1 << i);
            set.clear();
            for (int num : nums) {
                num = ((num >> i) << i); 
                set.add(num);
                if (set.contains(num ^ better)) { 
                    ans = better;
                    break;
                }
            }
        }
        return ans;
    }
}

}
